package com.example.concurrency.example;

import com.example.concurrency.annoations.Recommend;
import com.example.concurrency.annoations.ThreadSafe;

/**
 * 单例模式：枚举写法
 *
 * @author verlet
 * @date 2018/7/22
 */
@ThreadSafe
@Recommend
public class Singleton {

    private Singleton(){

    }

    public static Singleton getInstance(){
        return Single.INSTANCE.getInstance();
    }

    private enum Single{
        /**
         *
         */
        INSTANCE;

        private Singleton singleton;

        /**
         * jvm保证只执行一次
         */
        Single(){
            singleton = new Singleton();
        }

        public Singleton getInstance(){
            return singleton;
        }
    }

}
